import { MessageSuccess } from "@/utils";
import { useFlowStore } from "@/store/modules/flow/flowStore";
import { NodeApi } from "@/api/NodeApi";

class FlowNodeDataApi {
  constructor () {
    this.FlowStore = useFlowStore()
  }

  async Install (NodeId, Params, NodeName, isPreCompiling = false, NodeTimeOut = 0) {
    const CurrentFlow = this.FlowStore.CurrentFlow
    const Param = {
      FlowId: CurrentFlow.id,
      NodeItemParamsJson: JSON.stringify(Params),
      NodeId: NodeId,
      NodeName: NodeName,
      NodeTimeOut: NodeTimeOut,
      IsPreCompiling: isPreCompiling,
    }
    const nd = await NodeApi.UpdateNodeParam(Param)
    if (nd.IsSuccess && !isPreCompiling) {
      MessageSuccess('保存成功')
    }

    return nd
  }
}

export default FlowNodeDataApi
